package gtkwire.gobject;


/**
* This class describes a subset of GObject type system. It is used to commicate type 
* information when required by GTK+, for example when creating GtkTreeModel and setting column types.
* <p>
* Generally only types used in java are used because data types not availble in java are
* of no interest when creating java programs. Exeption is  GDK_TYPE_PIXBUF which is used to set 
* treemodel column to display images.
*/
public class GType
{
	//-------------------------------------------------- G_type codes
	private static final int G_TYPE_INVALID = 0;
//	private static final int G_TYPE_NONE = 1;
//	private static final int G_TYPE_INTERFACE = 2;
//	private static final int G_TYPE_CHAR = 3;
//	private static final int G_TYPE_UCHAR = 4; 
	private static final int G_TYPE_BOOLEAN = 5;
	private static final int G_TYPE_INT = 6;
//	private static final int G_TYPE_UINT = 7;
//	private static final int G_TYPE_LONG = 8;
//	private static final int G_TYPE_ULONG = 9;
//	private static final int G_TYPE_INT64 = 10;
//	private static final int G_TYPE_UINT64 = 11;
//	private static final int G_TYPE_ENUM = 12;
//	private static final int G_TYPE_FLAGS = 13;
	private static final int G_TYPE_FLOAT = 14;
	private static final int G_TYPE_DOUBLE = 15;
	private static final int G_TYPE_STRING = 16;
//	private static final int G_TYPE_POINTER = 17;
//	private static final int G_TYPE_BOXED = 18;
//	private static final int G_TYPE_PARAM  = 19;
//	private static final int G_TYPE_OBJECT = 20;
//	private static final int G_TYPE_GTYPE = 21;
	private static final int GDK_TYPE_PIXBUF = 22;

	//------------------------------------------- GTypes
	/**
	* Invalid data type.
	*/
	public static final GType INVALID = new GType(G_TYPE_INVALID);
//	public static final GType NONE = new GType( G_TYPE_NONE);
//	public static final GType INTERFACE = new GType( G_TYPE_INTERFACE);
//	public static final GType CHAR = new GType( G_TYPE_CHAR);
//	public static final GType UCHAR = new GType( G_TYPE_UCHAR);
	/**
	* Gtype for boolean or Boolean.
	*/
	public static final GType BOOLEAN = new GType(G_TYPE_BOOLEAN);
	/**
	* Gtype for int or Integer 
	*/
	public static final GType INT = new GType(G_TYPE_INT);
//	public static final GType UINT = new GType(G_TYPE_UINT);
//	public static final GType LONG = new GType(G_TYPE_LONG);
//	public static final GType ULONG = new GType(G_TYPE_ULONG);
//	public static final GType INT64 = new GType(G_TYPE_INT64);
//	public static final GType UINT64 = new GType(G_TYPE_UINT64);
//	public static final GType ENUM = new GType(G_TYPE_ENUM);
//	public static final GType FLAGS = new GType(G_TYPE_FLAGS);
	/**
	* Gtype for float or Float
	*/
	public static final GType FLOAT = new GType(G_TYPE_FLOAT);
	/**
	* Gtype for double or Double
	*/
	public static final GType DOUBLE = new GType(G_TYPE_DOUBLE);
	/**
	* Gtype for String.
	*/
	public static final GType STRING = new GType(G_TYPE_STRING);
//	public static final GType POINTER = new GType(G_TYPE_POINTER);
//	public static final GType BOXED = new GType(G_TYPE_BOXED);
//	public static final GType PARAM  = new GType(G_TYPE_PARAM);
//	public static final GType OBJECT = new GType(G_TYPE_OBJECT);
//	public static final GType GTYPE = new GType(G_TYPE_GTYPE);
	/**
	* Gtype for GdkPixBuf.
	*/
	public static final GType GDK_PIXBUF = new GType(GDK_TYPE_PIXBUF);

	private int code = -1;
	
	private GType( int code )
	{
		this.code = code;
	}

	/**
	* Type as int.
	*/
	public int getCode(){ return code; }
	/**
	* Type int as String.
	*/
	public String getCodeStr(){ return Integer.toString( code ); }

	/* Converts GValue to String */
	/**
	* Returns String representation of value of GType.
	*/
	public static String getValString( GType type, Object value )
	{
		int typeCode = type.getCode();
		switch( typeCode )
		{
			case G_TYPE_STRING:
				return (String) value;

			case G_TYPE_INT:
				return ((Integer)value).toString();

			case G_TYPE_BOOLEAN:
				return ((Boolean)value).toString();

			case G_TYPE_DOUBLE:
				return ((Double)value).toString();

			case G_TYPE_FLOAT:
				return ((Float)value).toString();

			case GDK_TYPE_PIXBUF:
				return((GdkPixBuf)value).getData();

			default:
				return null;
		}
	}

}//end class